﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;
using WaterRevenueMS.Core.Repository.BaseData;
using WaterRevenueMS.Domain.ViewModels.BaseData;
using WaterRevenueMS.Componnent.Entities.BaseData;


namespace WaterRevenueMS.Core.Service.BaseData.Impl
{
    [Export(typeof(IAreaService))]
    public class AreaService : CoreServiceBase,IAreaService
    {
        [Import]
        public IAreaRepository AreaRepository { get; set; }
        public IQueryable<Componnent.Entities.BaseData.Area> Areas
        {
            get { return AreaRepository.Entities; }
        }

        public Componnent.Common.OperationResult Insert(Domain.ViewModels.BaseData.Area.AreaModel model)
        {
            var entity = new Area
            {

                Dan_WSZ_No = model.CompanyId != 0 ? model.CompanyId : null,
                Chao_BY_No = model.ChaoBiao_ID != 0 ? model.ChaoBiao_ID : null,
                Qu_YMC = model.Qu_YMC,
                Qu_YBH = model.Qu_YBH,
                CreateDT = DateTime.Now,
                ReviseDT = DateTime.Now 

            };
            AreaRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public Componnent.Common.OperationResult Update(Domain.ViewModels.BaseData.Area.AreaModel model)
        {
            var entity = new Area
            {
                Id = model.id,
                Dan_WSZ_No = model.CompanyId != 0 ? model.CompanyId : 0,
                Chao_BY_No = model.ChaoBiao_ID != 0 ? model.ChaoBiao_ID : 0,
                Qu_YMC = model.Qu_YMC,
                Qu_YBH = model.Qu_YBH,
                ReviseDT = DateTime.Now 

            };
            AreaRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public Componnent.Common.OperationResult Delete(int Id)
        {
            var model = Areas.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;

            AreaRepository.Delete(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
